package nl.infodation.emr.pricingservice.ui;

import java.util.ArrayList;
import java.util.List;

import nl.infodation.emr.pricingservice.data.Item;
import nl.infodation.emr.pricingservice.ui.component.ExplicitPagingContainer;
import nl.infodation.emr.pricingservice.ui.page.SessionData;
import nl.infodation.emr.utility.Constants;

import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Table;

@SuppressWarnings({"rawtypes", "unchecked"})
public class LoadedRulesList extends Table {
	
	private static final long serialVersionUID = 1L;
	final private ExplicitPagingContainer pagingContainer=new ExplicitPagingContainer();
	
	public Object[] STANDARD_COL_NAME;
	
	public String[] STANDARD_COL_HEADER;
	
	private void initColumnData() {
		STANDARD_COL_NAME = new Object[] {
				"value",
			};
		
		STANDARD_COL_HEADER = new String[] {
				SessionData.getI18N().getMessage(Constants.ITEM_HEADER),
			};
	}
	
	public LoadedRulesList(){
		initColumnData();
		setSizeFull();
		initializePagingContainer();
		setContainerDataSource(pagingContainer);
		setVisibleColumns(STANDARD_COL_NAME);
        setColumnHeaders(STANDARD_COL_HEADER);
        setColumnCollapsingAllowed(true);
        setColumnReorderingAllowed(true);
        setSelectable(true);
        setImmediate(true);
        setNullSelectionAllowed(false);
	}
	
	private void initializePagingContainer() {
		pagingContainer.addContainerProperty("value", String.class, null);
	}

	public int getPageSize()
	{
		return pagingContainer.getPageSize();
	}
	
	public void loadPage(int page) {
		
	}
	
	public void reload(){
	}
	
	public void setDataSource(final List<Item> items) {
		List<BeanItem> beans = new ArrayList<BeanItem>();
		for (Item item : items)
			beans.add(new BeanItem(item));
		
		pagingContainer.setDataSource(beans);
	}
}
